# $Id$
# Contributor: tobias <tobias@archlinux.org>
# Contributor: Tobias Kieslich <tobias@justdreams.de>

pkgname=(libgda libgda-{firebird,jdbc,mysql,postgres})
pkgver=5.2.4
pkgrel=8
pkgdesc="Database access library"
url="http://www.gnome-db.org/"
arch=(i686 x86_64)
license=(GPL)
depends=(gtksourceview3 libxslt python2 libsecret graphviz goocanvas iso-codes)
makedepends=(glade libmariadbclient postgresql-libs libfbclient jdk8-openjdk intltool
             gobject-introspection gtk-doc vala itstool gnome-common git)
_commit=2ea3179bad2e414ff6068db2249116eb6e2564a5  # tags/LIBGDA_5_2_4^0
source=("git+https://git.gnome.org/browse/libgda#commit=$_commit"
        java.patch)
sha256sums=('SKIP'
            'e28ea88d49bcb91fa6907440a6785a508fb681c463188b3805509773f5d0fc22')

_apiver=5.0

pkgver() {
  cd $pkgname
  git describe --tags | sed 's/^LIBGDA_//;s/_/./g;s/-/+/g'
}

prepare() {
  mkdir providers

  cd $pkgname

  patch -Np1 -i ../java.patch
  javac getsp.java

  find -name '*.py' -exec sed -i '1s/python$/&2/' {} +

  NOCONFIGURE=1 ./autogen.sh
}

build() {
  cd $pkgname
  ./configure --prefix=/usr --sysconfdir=/etc --disable-static \
      --with-bdb=/usr --with-bdb-libdir-name=lib \
      --enable-json --enable-system-sqlite --enable-binreloc \
      --enable-gda-gi --enable-gdaui-gi \
      --enable-vala --enable-gdaui-vala VALA_API_VERSION=0.36 \
      --enable-gtk-doc --disable-crypto
  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool
  make
}

package_libgda() {
  optdepends=('libgda-firebird: provider for Firebird'
              'libgda-jdbc: provider for JDBC'
              'libgda-mysql: provider for MySQL'
              'libgda-postgres: provider for PostgreSQL')
  options+=(emptydirs)

  cd $pkgname
  make DESTDIR="$pkgdir" install

  for _provider in firebird jdbc mysql postgres; do
    mv "$pkgdir"/usr/lib/libgda-$_apiver/providers/libgda-${_provider}[-.]*so \
       "$pkgdir"/usr/lib/pkgconfig/libgda-${_provider}-${_apiver}.pc \
       "$pkgdir"/usr/share/libgda-$_apiver/${_provider}_specs_*.xml \
       "$srcdir/providers"
  done

  mv "$pkgdir"/usr/lib/libgda-$_apiver/providers/gdaprovider-${_apiver}.jar \
     "$pkgdir"/usr/bin/gda-list-jdbc-providers-${_apiver} \
     "$srcdir/providers"
}

_packageprovider() {
  install -d "$pkgdir"/usr/lib/{pkgconfig,libgda-$_apiver/providers} \
             "$pkgdir"/usr/share/libgda-$_apiver
  mv providers/libgda-${1}[-.]*so "$pkgdir/usr/lib/libgda-$_apiver/providers"
  mv providers/libgda-${1}-5.0.pc "$pkgdir/usr/lib/pkgconfig"
  mv providers/${1}_specs_*.xml "$pkgdir/usr/share/libgda-$_apiver"
}

package_libgda-firebird() {
  pkgdesc="libgda provider for Firebird"
  depends=(libgda libfbclient)
  _packageprovider firebird
}

package_libgda-jdbc() {
  pkgdesc="libgda provider for JDBC"
  depends=(libgda java-environment)
  _packageprovider jdbc
  install -d "$pkgdir/usr/bin"
  mv providers/gda-list-jdbc-providers-${_apiver} "$pkgdir/usr/bin"
  mv providers/gdaprovider-${_apiver}.jar "$pkgdir/usr/lib/libgda-$_apiver/providers"
}

package_libgda-mysql() {
  pkgdesc="libgda provider for MySQL"
  depends=(libgda libmariadbclient)
  _packageprovider mysql
}

package_libgda-postgres() {
  pkgdesc="libgda provider for PostgreSQL"
  depends=(libgda postgresql-libs)
  _packageprovider postgres
}
